package com.xywh.composeLibrary.view

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FabPosition
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.sp

/**
 *
 * @param containerColor Color 标题背景颜色
 * @param titleColor Color 标题文字颜色
 * @param title String 标题内容
 * @param navigationIconImageVector ImageVector 左侧按钮图片
 * @param navigationIconOnClick Function0<Unit> 左侧按钮点击事件
 * @param actionsIconImageVector ImageVector 右侧图片
 * @param actionsIconOnClick Function0<Unit> 右侧按钮点击事件
 * @param isActionsShow Boolean 是否显示右侧按钮
 * @param isnNvigationShow Boolean 是否显示左侧按钮
 * @param content [@androidx.compose.runtime.Composable] Function1<PaddingValues, Unit> 头部标题下面的内容
 */
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@Composable
fun XxTopAppBarCenter(
    containerColor: Color = MaterialTheme.colorScheme.primary,
    titleColor: Color = Color.White,
    title: String,
    navigationIconImageVector: ImageVector = Icons.Filled.ArrowBack,
    navigationIconOnClick: () -> Unit = {},
    actionsIconImageVector: ImageVector = Icons.Filled.Menu,
    actionsIconOnClick: () -> Unit = { },
    isActionsShow: Boolean = false,
    isnNvigationShow: Boolean = true,
    floatingActionButton: @Composable () -> Unit = {},
    floatingActionButtonPosition: FabPosition = FabPosition.End,
    content: @Composable (PaddingValues) -> Unit
) {
    Scaffold(
        topBar = {
            CenterAlignedTopAppBar(
                colors = TopAppBarDefaults.topAppBarColors(
                    containerColor = containerColor
                ),
                title = {
                    Text(
                        title,
                        color = titleColor,
                        modifier = Modifier
                            .basicMarquee(),
                        fontSize = 16.sp
                    )
                },
                navigationIcon = {
                    if (isnNvigationShow)
                        IconButton(onClick = {
                            navigationIconOnClick.invoke()
                        }) {
                            Icon(
                                imageVector = navigationIconImageVector,
                                contentDescription = "Back",
                                tint = titleColor

                            )
                        }
                },

                actions = {
                    if (isActionsShow) {
                        IconButton(onClick = {
                            actionsIconOnClick.invoke()
                        }) {
                            Icon(
                                imageVector = actionsIconImageVector,
                                contentDescription = "Menu",
                                tint = titleColor
                            )
                        }
                    }
                }
            )

        },
        floatingActionButtonPosition = floatingActionButtonPosition,
        floatingActionButton = floatingActionButton,
        content = { innerPadding ->
            content(innerPadding)
        }

    )
}

